package com.kirayous.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.kirayous.api.admin.service.IMenuService;
import com.kirayous.common.Result;
import com.kirayous.common.dto.LabelOptionDTO;
import com.kirayous.common.dto.MenuDTO;
import com.kirayous.common.dto.UserMenuDTO;
import com.kirayous.common.entity.Menu;
import com.kirayous.common.vo.ConditionVO;
import com.kirayous.common.vo.MenuVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Objects;

/**
 * @author KiraYous
 * @version V1.0
 * @Package com.kirayous.admin.controller
 * @date 2021/9/9 18:32
 */
@RestController
@Api(tags = "菜单展示模块")
public class MenuController {

    @Autowired
    private IMenuService menuService;

    @ApiOperation(value = "查看菜单列表--可条件查询")
    @GetMapping ("/admin/menus")
    public Result listMenus(/*这里不需要加@RequestBody*/ ConditionVO conditionVO) {
        List<MenuDTO> list=menuService.listMenus(conditionVO);
        return Result.success().setData(list);
    }

//    @ApiOperation(value = "查看用户菜单")
//    @GetMapping("/admin/user/menus")
//    public Result listUserMenus() {
//        List<MenuDTO> list=menuService.listMenus();
//        return Result.success().setData(list);
//
//    }

    @ApiOperation(value = "查看用户菜单")
    @GetMapping("/admin/user/menus")
    public Result listUserMenus() {
        List <UserMenuDTO> list=menuService.listUserMenus();
        return Result.success().setData(list);
    }
    /**
     * 新增或修改菜单
     *
     * @param menuVO 菜单
     * @return {@link Result<>}
     */
    @ApiOperation(value = "新增或修改菜单")
    @PostMapping("/admin/menus")
    public Result saveOrUpdateMenu(@Valid @RequestBody(required = false) Menu menuVO) {
        menuService.saveOrUpdateMenu(menuVO);
        return Result.success();
    }

    /**
     * 删除菜单
     *
     * @param menuId 菜单id
     * @return {@link Result<>}
     */
    @ApiOperation(value = "删除菜单")
    @DeleteMapping("/admin/menus/{menuId}")
    public Result deleteMenu(@PathVariable("menuId") Integer menuId){
        menuService.deleteMenu(menuId);
        return Result.success();
    }

    @ApiOperation(value = "是否隐藏菜单——包括子菜单")
    @PutMapping("/admin/toHiddenMenus")
    public Result toHiddenMenu(@RequestBody MenuVO menuVO){
//        System.out.println(menuVO);
        menuService.toHiddeneMenu(menuVO);
        return Result.success();
    }

    /**
     * 查看角色菜单选项
     *
     * @return 查看角色菜单选项
     */
    @ApiOperation(value = "查看角色菜单选项")
    @GetMapping("/admin/role/menus")
    public Result listMenuOptions() {
        return Result.success().setData(menuService.listMenuOptions());
    }
}
